< previous page page_144 next page >

Page 144
Puzzle 32
Animating Rectangles
One of the interesting user interface effects you can see under Windows 95 and Windows NT occurs when you minimize or maximize a window. When minimized, a window seems to collapse into the taskbar. This animated effect is provided by a cool function called DrawAnimatedRects, defined as follows in the Win32 documentation:
BOOL WINAPI DrawAnimatedRects(
    HWND hwnd,   // handle to clipping window
    int idAni,   // type of animation
    CONST RECT *lprcFrom,// pointer to rectangle coordinates (minimized)
    CONST RECT *lprcTo   // pointer to rectangle coordinates (restored)
   );
The hwnd parameter is the window in which the animation should occur. When the window handle is 0, the animation occurs on the desktop instead of within a specified window.
The idAni parameter is one of the following constants:
Private Const IDANI_OPEN = 1
Private Const IDANI_CLOSE = 2
Private Const IDANI_CAPTION = 3
IDANI_OPEN indicates that the rectangle animation should open from the minimized to the restored position. IDANI_CLOSE indicates that the rectangle animation should close from the restored to the minimized position. IDANI_CAPTION indicates that only the caption should be animated.
The lprcFrom and lprcTo parameters are pointers to RECT structures, which contain four 32-bit fields describing the left, top, width, and height of the rectangle.
The Rects.vbp sample program (on the CD that comes with this book) demonstrates the use of this function to animate a captionwhich initially has a height and width of 0 at the center of the windowto fill the entire window. The ScaleMode property of the form is set to vbPixels to make sure there is no confusion between twips and pixels in the rectangle coordinates.

 
< previous page page_144 next page >